<div class="main-content">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			var global_company_id = -1; 
			var global_date1 = '';
			var global_date2 = '';
			$(document).ready(function () {
				make_company_list();
			});
		</script>

		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
				<a href="#">系统首页</a>
			</li>
			<li class="active">
				报表管理
			</li>
            <li class="active">
				公司统计
			</li>
		</ul><!-- .breadcrumb -->
	</div>
	<div class="page-content">
    	<div class="row">
    	    <div class="page-header">
    			<h1>公司统计</h1>
    		</div>
    		<div class=" col-md-12 col-sm-12 col-xs-12 form">
                <div class="row">
                <form action="<?php echo base_url().'admin/count/query_company_count'?>" method="get">
                    <div class="col-xs-6">
                    	<label>选择周期：</label>
                        <input type="text"  name="date1" id="date1" value="<?php if (isset($date1))echo $date1;?>" style="display: inline-block;width:25%;" />
                        <label style="display: inline-block;">———</label>
                        <input id="date2" name="date2" style="display: inline-block;width:25%;" value="<?php if (isset($date2))echo $date2;?>" type="text" class="form-control">
                        <button class="btn btn-sm btn-info" type="submit"><i class="icon-search"></i>统计</button> 
                            <a id="excel_btn" class="btn btn-sm btn-warning" href="<?php echo base_url().'admin/count/company_excel';?>" style="display: none;"><i class="icon-download"></i>导出</a>
                    </div>
                </form>
                </div>
            </div>
            
            <br><br>
            
            <div class="col-sm-12" >
			     <div class="widget-box">
    			     <div class="widget-body">
    			         <div class="widget-header widget-header-flat widget-header-small">
        					<h5>
        						<i class="icon-signal"></i>
        						  按公司统计
        					</h5>
    					</div>
    					<div id="main_info_1" ></div>
    				</div>
			     </div>
		    </div>
		    <div class="col-xs-12 margin_t margin_b">
				<div class="table-responsive  tab">
					<table id="company_tab" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>姓名</th>
								<th>性别</th>
                                <th>年龄</th>
                                <th>手机号码</th>
                                <th>身份证号</th>
                                <th>创建日期</th>
                                <th>家庭住址</th>
							</tr>
						</thead> 
						<tbody></tbody>
						</table>
                 </div><!-- /.table-responsive -->
			</div>
            </div><!-- /.row -->
		</div><!-- /.page-content -->
	</div><!-- /.main-content -->
	<script type="text/javascript">
	var main_info_1 = document.getElementById('main_info_1');
	
	//用于使chart自适应高度和宽度,通过窗体高宽计算容器高宽
	var resizeWorldMapContainer = function () {
		ht=window.innerHeight-140;
	    main_info_1.style.height = ht/2 +'px';
	};
	//设置容器高宽
	resizeWorldMapContainer();
	$(function(){
		loadData1();
	}); 
	var myChart_1 = echarts.init(document.getElementById('main_info_1'));
	function loadData1(){
		myChart_1.setOption({
    		tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                x: 'left',
                data: [<?php if (isset($result)&&count($result)>0){foreach ($result as $val){echo "'".$val->name."',";}}?>]
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {
                        show: true, 
                        type: ['pie', 'funnel'],
                        option: {
                            funnel: {
                                x: '25%',
                                width: '50%',
                                funnelAlign: 'left',
                                max: 1548
                            }
                        }
                    },
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            series : [
                {
                    name:'用户数量',
                    type:'pie',
                    radius : '55%',
                    center: ['50%', '60%'],
                    data:[
                          <?php if (isset($result)&&count($result)>0){
                              foreach ($result as $val){?>
                              {value:<?php echo $val->value;?>, name:<?php echo "'".$val->name."'";?>,company_id:<?php echo $val->id;?>},
                              <?php }
                        }?>
                          ]
                }
            ]
    	});
	}
	window.onresize = function () {
	    //重置容器高宽
	    resizeWorldMapContainer();
	    myChart_1.resize();
		
	}; 
	$(function () {
        $('#date1').datetimepicker({
            format: 'yyyy-mm-dd', 'autoclose': true, minView: 2,language: 'zh-CN'
        });
        $('#date2').datetimepicker({
            format: 'yyyy-mm-dd', 'autoclose': true, minView: 2,language: 'zh-CN'
        });
    });      
	myChart_1.on('click', function (param) {
		var company_id = param.data.company_id;
		var date1 = $('#date1').val();
		var date2 = $('#date2').val();
		reload_table(company_table,'<?php echo base_url().'admin/count/get_company_user/'?>'+company_id+'/'+date1+'/'+date2);
		$('#excel_btn').show();
	});
	var company_table;
	function make_company_list(){
		company_table = $('#company_tab').DataTable( {
				"processing": true, //Feature control the processing indicator.
		        "serverSide": true, //Feature control DataTables' server-side processing mode.
		        "ordering": false,
		        "lengthChange": false,
		        "language": {
					"zeroRecords": "没有找到记录",
					"info": "共_TOTAL_条记录",
					"infoEmpty": "共_TOTAL_条记录",
					"paginate": {
			            "first": "首页",
			            "previous": "上一页",
			            "next": "下一页",
			            "last": "末页"
			        },
				},
				"searching": false,
		        "ajax": {
		        	    "url": "<?php echo base_url().'admin/count/get_company_user/'?>"+global_company_id+'/'+global_date1+'/'+global_date2,
		                "type": "POST"
		        },
		    } );
	}
	function reload_table(name,url)
	{
		name.ajax.url(url).load(null,true); //reload datatable ajax 
	}
	</script>